package cn.tedu.controller;

import cn.tedu.dao.HttpDao;
import cn.tedu.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Http2Controller {
    @Autowired
    private HttpDao httpDao;

    @GetMapping("user")
    public String getUserAll(){
        List<User> list = httpDao.getUserAll();
        return list.toString();
    }

    //@PathVariable 表示获取请求路径中参数的值,并要求必须同名
    @GetMapping("user/{id}")
    public User getUser(@PathVariable int id) {
        User user = httpDao.getUser(id);
        return user;
    }

    @DeleteMapping("user/{id}")
    public String deleteUser(@PathVariable int id) {
        httpDao.deleteUser(id);
        return "删除成功";
    }
}
